package com.irdstudio.cdp.pboc.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.cdp.pboc.service.dao.PbocIdentityDao;
import com.irdstudio.cdp.pboc.service.domain.PbocIdentity;
import com.irdstudio.cdp.pboc.service.facade.PbocIdentityService;
import com.irdstudio.cdp.pboc.service.vo.PbocIdentityVO;
import com.irdstudio.basic.framework.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 身份信息				<p>
 * @author ligm
 * @date 2018-12-26
 */
@Service("pbocIdentityService")
public class PbocIdentityServiceImpl implements PbocIdentityService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PbocIdentityServiceImpl.class);

	@Autowired
	private PbocIdentityDao pbocIdentityDao;
	
	/**
	 * 新增操作
	 */
	public int insertPbocIdentity(PbocIdentityVO inPbocIdentityVo)  throws Exception {
		logger.debug("当前新增数据为:"+ inPbocIdentityVo.toString());
		int num = 0;
		try {
			PbocIdentity pbocIdentity = new PbocIdentity();
			beanCopy(inPbocIdentityVo, pbocIdentity);
			num = pbocIdentityDao.insertPbocIdentity(pbocIdentity);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PbocIdentityVO inPbocIdentityVo)  throws Exception {
		logger.debug("当前删除数据条件为:"+ inPbocIdentityVo);
		int num = 0;
		try {
			PbocIdentity pbocIdentity = new PbocIdentity();
			beanCopy(inPbocIdentityVo, pbocIdentity);
			num = pbocIdentityDao.deleteByPk(pbocIdentity);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocIdentityVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PbocIdentityVO inPbocIdentityVo)  throws Exception {
		logger.debug("当前修改数据为:"+ inPbocIdentityVo.toString());
		int num = 0;
		try {
			PbocIdentity pbocIdentity = new PbocIdentity();
			beanCopy(inPbocIdentityVo, pbocIdentity);
			num = pbocIdentityDao.updateByPk(pbocIdentity);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
			throw e;
		}
		logger.debug("根据条件:"+ inPbocIdentityVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PbocIdentityVO queryByPk(PbocIdentityVO inPbocIdentityVo) {
		
		logger.debug("当前查询参数信息为:"+ inPbocIdentityVo);
		try {
			PbocIdentity queryPbocIdentity = new PbocIdentity();
			beanCopy(inPbocIdentityVo, queryPbocIdentity);
			PbocIdentity queryRslPbocIdentity = pbocIdentityDao.queryByPk(queryPbocIdentity);
			if (Objects.nonNull(queryRslPbocIdentity)) {
				PbocIdentityVO outPbocIdentityVo = beanCopy(queryRslPbocIdentity, new PbocIdentityVO());
				logger.debug("当前查询结果为:"+ outPbocIdentityVo.toString());
				return outPbocIdentityVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
			throw e;
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocIdentityVO> queryAllOwner(PbocIdentityVO pbocIdentityVo)  throws Exception {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PbocIdentityVO> list = null;
		try {
			List<PbocIdentity> pbocIdentitys = pbocIdentityDao.queryAllOwnerByPage(pbocIdentityVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pbocIdentitys.size());
			pageSet(pbocIdentitys, pbocIdentityVo);
			list = (List<PbocIdentityVO>) beansCopy(pbocIdentitys, PbocIdentityVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocIdentityVO> queryAllCurrOrg(PbocIdentityVO pbocIdentityVo)  throws Exception {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PbocIdentity> pbocIdentitys = pbocIdentityDao.queryAllCurrOrgByPage(pbocIdentityVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pbocIdentitys.size());
		List<PbocIdentityVO> list = null;
		try {
			pageSet(pbocIdentitys, pbocIdentityVo);
			list = (List<PbocIdentityVO>) beansCopy(pbocIdentitys, PbocIdentityVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PbocIdentityVO> queryAllCurrDownOrg(PbocIdentityVO pbocIdentityVo)  throws Exception {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PbocIdentity> pbocIdentitys = pbocIdentityDao.queryAllCurrDownOrgByPage(pbocIdentityVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pbocIdentitys.size());
		List<PbocIdentityVO> list = null;
		try {
			pageSet(pbocIdentitys, pbocIdentityVo);
			list = (List<PbocIdentityVO>) beansCopy(pbocIdentitys, PbocIdentityVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
			throw e;
		}
		
		return list;
	
	}
}
